<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>Finalove-App-NewFriendDetails</title>
		<link rel="stylesheet" href="../../resource/font/css/font-awesome.min.css">
		<link rel="stylesheet" href="../../resource/css/mint.css">
		<link rel="stylesheet" href="../../resource/css/style.css">
		<script src="../../resource/js/vue.js"></script>
		<script src="../../resource/js/mint.min.js"></script>
		<script src="../../resource/js/jquery.min.js"></script>
		<style type="text/css">
			body{
				background-color: #f2f2f2;
			}
			.ct-box{
				margin-top: 40px;
				width: 90%;
				margin-left: 5%;
			}
			#userHeadImg {
				margin-top: 30px;
				margin-bottom: 30px;
				border-radius: 15px;
				border: 2px solid #ebeef5;
				box-shadow: 0 4px 12px 0 rgba(0,0,0,0.1);
			}
			.saveBtn {
				margin-top:30px;
			}
		</style>
	</head>
	<body>
		<div id="main">
			<mt-header fixed :title="title">
				<mt-button icon="back" slot="left" class="closeView"></mt-button>
			</mt-header>
			<div class="ct-box">
				<p class="text-center">
					<img id="userHeadImg" :src="friend.head" width="150px" height="150px">
				</p>
				<mt-field label="账号" v-model="friend.user_name" readonly></mt-field>
				<mt-field label="邮箱" v-model="friend.email" readonly></mt-field>
				<mt-field label="昵称" v-model="friend.nick_name" readonly></mt-field>
				<mt-button size="large" type="primary" class="saveBtn" @click="friendApply">添加好友</mt-button>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		var main = new Vue({
			el:"#main",
			data:{
				title:"添加好友详情",
				friend:{
					id:"",
					user_name:"",
					nick_name:"",
					email:"",
					head:""
				}
			},
			mounted:function() {
				this.init();
			},
			methods:{
				init() {
					// 获取配置
					$.getJSON('../../resource/config.json',function(res){
						main.api_prefix = res.api_prefix;
						main.api_key = res.api_key;
						main.app_version = res.app_version;
						main.app_version_check_url = res.app_version_check_url;
					});
					// loading
					document.addEventListener('plusready',function () {
						// 沉浸header
						plus.navigator.setFullscreen(true);
						// header返回btn
						document.querySelector(".closeView").addEventListener('click',function(){
							plus.webview.currentWebview().close();
						});
						// backbutton事件修改
						plus.key.addEventListener('backbutton', function() {
							plus.webview.currentWebview().close();
							return false;
						}, false);
						// 获取参数
						main.friend = {
							id:plus.webview.currentWebview().param.id,
							user_name:plus.webview.currentWebview().param.user_name,
							nick_name:plus.webview.currentWebview().param.nick_name,
							email:plus.webview.currentWebview().param.email,
							head:plus.webview.currentWebview().param.head,
						}
						main.title = main.friend.nick_name;
					})
				},
				friendApply() {
					if(this.friend.id == plus.storage.getItem("user_id")){
						main.$toast({message:'不能添加自己为好友哦~',position:'bottom',duration: 1500});
						return false;
					}
					var url = this.api_prefix + "friends/friendApply";
					var param = {
						api_key:this.api_key,
						params:{
							to_id:this.friend.id,
							from_id:plus.storage.getItem("user_id")
						},
					}
					$.post(url,param,function(res) {
						main.$toast({message:res.msg,position:'bottom',duration: 1500});
					});
				}
			}
		})
	</script>
</html>
